<template>
    <div>

        <h1>医生信息添加</h1>
        <a href="/showys">医生信息显示</a>
<br>
          <table class="table">
             <tbody>
                <tr>
                    <td>医生姓名</td>
                    <td>
                        <input type="text" v-model="data.ysName">
                    </td>
                </tr>
                <tr>
                    <td>头像</td>
                    <td>
                        <input type="file" @change="ImgUrlys">
                        <img :src="'https://localhost:7293/'+data.imgUrl" style="height: 60px; width: 60px;">
                    </td>
                </tr>
                <tr>
                    <td>所属科室</td>
                    <td>
                         <select v-model="data.keshiid">
            <option :value="0">请选择科室</option>
            <option v-for="e in ksxlk" :value="e.id">{{ e.ksName }}</option>
        </select>
                    </td>
                </tr>
                <tr>
                    <td>创建日期</td>
                    <td>
                        <input type="date" v-model="data.ysDate">
                    </td>
                </tr> 
                <tr>
                    <td colspan="2">
                        <input type="button" value="添加" @click="add"> 
                    </td>
                </tr>
             </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router=useRouter();
onMounted(()=>{
    KSXLKS();
})
//科室下拉框
const ksxlk=ref([{
    "id": 1,
    "ksName": "骨科",
    "kScount": 15,
    "ksms": "",
    "ksDate": "2025-05-30T00:00:00",
    "isDelete": true
}]) 
const KSXLKS=()=>{
    axios.get("/api/HouseKS/XLKks").then(res=>{
        ksxlk.value=res.data
    })
} 
//上传
const ImgUrlys=(e:any)=>{
    var f = e.target.files[0];
    var fs = new FormData();
     
    fs.append("file",f);

    if(f.size>1024*1024*2)
{
    alert("图片大小不能超过2MB");
    return;
}
    debugger

    axios.post("/api/ImgUrl",fs).then(res=>{
        data.value.imgUrl=res.data;
    })
     
}


const data=ref({
  "id": 0,
  "ysName": "",
  "imgUrl": "",
  "keshiid": 0,
  "ysDate": "2025-05-19T04:00:27.148Z"
})

const add=()=>{

    if(data.value.ysName=="")
{
    alert("姓名不能为空");
    return;
}

    axios.post("/api/HouseYS/AddYs",data.value).then(res=>{
         if(res.data>0)
      {
        alert("添加成功")
        router.push({path:"/showys"})
      }
      else{
        alert("添加失败");
        return;
      }
    })
}


</script>

<style scoped>

</style>    